﻿using Dong8Triggers;
using LitJson2;
using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.AccessControl;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
//using dong8_utils;
public class CLRTriggers
{


    //public static readonly long RemoteId =1002;//Convert.ToInt64(getLocalORRemoteId("RemoteId"));
    public static readonly string LocalId = getLocalORRemoteId("LocalId");
    //详细log开关，=true就记录详细的log
    public static readonly bool @switch = false;

    //sys_workshop代码

    #region ※1 sys_workshop_financial_method
    [SqlTrigger(Name = @"sys_workshop_financial_method", Target = "[dbo].[sys_workshop]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void sys_workshop_financial_method()
    {
        string insertedSql = @"select SHOP_CODE,SHOP_ID,NAMEC,NAMEE,PARENT_ID,MEMO,SHOP_TYPE,IS_POS,IS_STOCK,club_id,checkin,type,issuekey,issuecard,issuecdno,COMPANY_ID,ifbuildclass,pcmak,pcip,pcDBMS,pcDatabase,pcServerName,pcLogId,pcLogPass,pcDBParm,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,bm_ck,fdeptNo,bm_zb_ck,fifhx,fifswim,fiffitnes,fifhotel,fifcy,fifi6,fifzbworksh,fuserdesk,fifzbworkzh FROM INSERTED;";
        string deletedSql = @"select SHOP_CODE,SHOP_ID,NAMEC,NAMEE,PARENT_ID,MEMO,SHOP_TYPE,IS_POS,IS_STOCK,club_id,checkin,type,issuekey,issuecard,issuecdno,COMPANY_ID,ifbuildclass,pcmak,pcip,pcDBMS,pcDatabase,pcServerName,pcLogId,pcLogPass,pcDBParm,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,bm_ck,fdeptNo,bm_zb_ck,fifhx,fifswim,fiffitnes,fifhotel,fifcy,fifi6,fifzbworksh,fuserdesk,fifzbworkzh FROM DELETED;";
        string tableName = "sys_workshop";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //sys_user代码

    #region ※2 sys_user_financial_method
    [SqlTrigger(Name = @"sys_user_financial_method", Target = "[dbo].[sys_user]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void sys_user_financial_method()
    {
        string insertedSql = @"select USER_ID,USER_SNO,USER_NAMEC,USER_NAMEE,USER_DESCRIPTION,USER_TYPE,USER_LEVEL,USER_STATUS,PASSWD,PASSWD_CONFIRM,IS_NEXTPASS,IS_USERPASS,IS_EMPTYPASS,IS_FOREVERPASS,ACC_LOCK,ACC_LOCK_TIME,PASS_LAST_TIME,TIME_CREATE,TIME_LIMIT,MAX_DISCOUNT,DEPT_ID,WORKSHOP_ID,IS_ICCARD,OTHER_ID,empid,sex,birthdate,province,city,addrhome,telhome,telcontact,addrcontact,zipcode,diploma,salary,subclub,subclubname,startdate,dept,deptname,type,recomm,resume,picture,isuser,bm,mc,user_pass,user_pass_q,group_id,n_last,fEntityNo,pcno,fcreatedate,fmodifydate,fDeptNo,fUserNo,ifdown,FuserLevel,FloginTimeType,FFunctRole,FaccountProp,rep_pcno,fdeptNoman,fworkbokec,vch_operID,vch_operator,vch_password,ch_flag,vch_empno,ch_deptno,int_discount,num_present,num_free,int_report_rate,ch_pre_mode,num_present_month,vch_cardid,ch_view_material_price_flag,int_present_rate,FClub,Fpcno,Code,Password,Name,EmployeeID,GroupID,fpowertype,FClubacc,fvisibleacc,facc_lock_rep,fpoweracc,salerate,fpoweracce,fpowerbill,yddiscount,fnotidicin,sgdsh,cgdsh,dbdsh,rkdsh,thdsh,int_zfgs,fusertype,Fposuserid FROM INSERTED;";
        string deletedSql = @"select USER_ID,USER_SNO,USER_NAMEC,USER_NAMEE,USER_DESCRIPTION,USER_TYPE,USER_LEVEL,USER_STATUS,PASSWD,PASSWD_CONFIRM,IS_NEXTPASS,IS_USERPASS,IS_EMPTYPASS,IS_FOREVERPASS,ACC_LOCK,ACC_LOCK_TIME,PASS_LAST_TIME,TIME_CREATE,TIME_LIMIT,MAX_DISCOUNT,DEPT_ID,WORKSHOP_ID,IS_ICCARD,OTHER_ID,empid,sex,birthdate,province,city,addrhome,telhome,telcontact,addrcontact,zipcode,diploma,salary,subclub,subclubname,startdate,dept,deptname,type,recomm,resume,picture,isuser,bm,mc,user_pass,user_pass_q,group_id,n_last,fEntityNo,pcno,fcreatedate,fmodifydate,fDeptNo,fUserNo,ifdown,FuserLevel,FloginTimeType,FFunctRole,FaccountProp,rep_pcno,fdeptNoman,fworkbokec,vch_operID,vch_operator,vch_password,ch_flag,vch_empno,ch_deptno,int_discount,num_present,num_free,int_report_rate,ch_pre_mode,num_present_month,vch_cardid,ch_view_material_price_flag,int_present_rate,FClub,Fpcno,Code,Password,Name,EmployeeID,GroupID,fpowertype,FClubacc,fvisibleacc,facc_lock_rep,fpoweracc,salerate,fpoweracce,fpowerbill,yddiscount,fnotidicin,sgdsh,cgdsh,dbdsh,rkdsh,thdsh,int_zfgs,fusertype,Fposuserid FROM DELETED;";
        string tableName = "sys_user";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //sys_payment代码

    #region ※3 sys_payment_financial_method
    [SqlTrigger(Name = @"sys_payment_financial_method", Target = "[dbo].[sys_payment]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void sys_payment_financial_method()
    {
        string insertedSql = @"select code,name_e,name_c,if_account,if_efficieny,account_code,type,memo,parent_code,money_type,payment_type,bank_service,parent_type,detail_type,if_sat,type_workshop,type_code,touch_disp,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fcoupinput,fifrepacc,fbillpos FROM INSERTED;";
        string deletedSql = @"select code,name_e,name_c,if_account,if_efficieny,account_code,type,memo,parent_code,money_type,payment_type,bank_service,parent_type,detail_type,if_sat,type_workshop,type_code,touch_disp,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fcoupinput,fifrepacc,fbillpos FROM DELETED;";
        string tableName = "sys_payment";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //syskindacc代码

    #region ※4 syskindacc_financial_method
    [SqlTrigger(Name = @"syskindacc_financial_method", Target = "[dbo].[syskindacc]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void syskindacc_financial_method()
    {
        string insertedSql = @"select code,name,namee,fifsysset,parentcode,type,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,WORKSHOP_ID,fvch_printer,syscode,otherkm1,otherkmname1,otherkm2,otherkmname2,paynamev,sale_kinds1 FROM INSERTED;";
        string deletedSql = @"select code,name,namee,fifsysset,parentcode,type,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,WORKSHOP_ID,fvch_printer,syscode,otherkm1,otherkmname1,otherkm2,otherkmname2,paynamev,sale_kinds1 FROM DELETED;";
        string tableName = "syskindacc";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //fitness_checkin代码

    #region ※5 fitness_checkin_financial_method
    [SqlTrigger(Name = @"fitness_checkin_financial_method", Target = "[dbo].[fitness_checkin]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void fitness_checkin_financial_method()
    {
        string insertedSql = @"select sid,cardno,cname,sex,mem_status,mem_type,checkin_date,checkin_time,operator,checkin_status,if_towel,if_keyring,keyno,if_returnkey,checkouttime,memo,color,memiden,memid,workshop,expendcard,deposit,guesttype,issuecard,lockstatus,clubcode,posflag,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fmp,ifinshoes,ifshoes,shoesdate1,fbillNo,fmpdate,shoesdate2,ifoutshoes,fgphzs,fbphzs,fsalempdttime,ifcusttype,fje,fqry,fcusttdno,fbillNosub,city_id,fmpsttdate,fmpenddate,fmpusermin,fmpdaycount,shoesdate4,fmpjeall,fyjjeall,finje,ftime_mode,fhyshitem FROM INSERTED;";
        string deletedSql = @"select sid,cardno,cname,sex,mem_status,mem_type,checkin_date,checkin_time,operator,checkin_status,if_towel,if_keyring,keyno,if_returnkey,checkouttime,memo,color,memiden,memid,workshop,expendcard,deposit,guesttype,issuecard,lockstatus,clubcode,posflag,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fmp,ifinshoes,ifshoes,shoesdate1,fbillNo,fmpdate,shoesdate2,ifoutshoes,fgphzs,fbphzs,fsalempdttime,ifcusttype,fje,fqry,fcusttdno,fbillNosub,city_id,fmpsttdate,fmpenddate,fmpusermin,fmpdaycount,shoesdate4,fmpjeall,fyjjeall,finje,ftime_mode,fhyshitem FROM DELETED;";
        string tableName = "fitness_checkin";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //pos_bill_payment代码

    #region ※6 pos_bill_payment_financial_method
    [SqlTrigger(Name = @"pos_bill_payment_financial_method", Target = "[dbo].[pos_bill_payment]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void pos_bill_payment_financial_method()
    {
        string insertedSql = @"select paymentid,billcode,rec_status,pay_status,paymethod,payparent,payamount,payforeign,payshop,paydate,payflag,payrate,payfamt,paychanges,paycardno,ExpiryDate,paysysid,payname,userid,shiftno,if_invoice,if_revenue,payno,paymemo,paytype,memid,clubcode,fit_paymentid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,syscode,paycode,sale_kinds,sale_category,sale_special,fifrepacc,fifdhyhpay,Fposuserid,Fbankcard,billcodepos,Fposid FROM INSERTED;";
        string deletedSql = @"select paymentid,billcode,rec_status,pay_status,paymethod,payparent,payamount,payforeign,payshop,paydate,payflag,payrate,payfamt,paychanges,paycardno,ExpiryDate,paysysid,payname,userid,shiftno,if_invoice,if_revenue,payno,paymemo,paytype,memid,clubcode,fit_paymentid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,syscode,paycode,sale_kinds,sale_category,sale_special,fifrepacc,fifdhyhpay,Fposuserid,Fbankcard,billcodepos,Fposid FROM DELETED;";
        string tableName = "pos_bill_payment";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //pos_sales代码

    #region ※7 pos_sales_financial_method
    [SqlTrigger(Name = @"pos_sales_financial_method", Target = "[dbo].[pos_sales]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void pos_sales_financial_method()
    {
        string insertedSql = @"select saleid,billcode,grand_billcode,rec_status,sale_status,pay_status,sale_type,billshop,saleshop,payshop,produceshop,saledate,saletime,closedate,paydate,userid,itemcode,itemname1,itemname2,itemspec,saleprice,quantity,saletotal,discountpercent,discounttotal,gratuitypercent,gratuitytotal,rebatetotal,taxpercent,taxtotal,totalpayable,saleweight,stockprice,stockqty,modifier_memo,serverno,if_discount,if_gratuity,sale_prop,if_revenue,if_generate,if_other,if_invoice,closemethod,paymethod,checkin_id,orderno,seatno,printno,otherid,if_import,if_tax,pricemethod,sale_kinds,parent_kinds,sale_category,parent_category,sale_special,parent_special,stat_code,paymentid,fit_paymentid,payflag,itemid,autocdflag,otherflag,complimentary_flag,modifier,reason,kitchen_type,seat_no,is_meal,is_backup,meal_id,meal_type,is_inv,is_addtion,club_id,holidaymethod,clubcode,sttime,endtime,fcount_hh,fcount_mm,fcditemno,Fpcno,fclub,fEntityNo,fit_saleid,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,xh,dzxh,dj_cb,je_cb,bm_ck,is_check,walkcust_ftype,keyno,memno,Fremark,deposit,fcusttdno,fbillNosub,disccode,spandhyacc,ch_printflag,accuserid,fdayandhousr,fmpdaycount,zbcardno,v_artno,Fmp_m_id,acc_clubkinds1,acc_clubkinds2,acc_clubkinds3,fcustno FROM INSERTED;";
        string deletedSql = @"select saleid,billcode,grand_billcode,rec_status,sale_status,pay_status,sale_type,billshop,saleshop,payshop,produceshop,saledate,saletime,closedate,paydate,userid,itemcode,itemname1,itemname2,itemspec,saleprice,quantity,saletotal,discountpercent,discounttotal,gratuitypercent,gratuitytotal,rebatetotal,taxpercent,taxtotal,totalpayable,saleweight,stockprice,stockqty,modifier_memo,serverno,if_discount,if_gratuity,sale_prop,if_revenue,if_generate,if_other,if_invoice,closemethod,paymethod,checkin_id,orderno,seatno,printno,otherid,if_import,if_tax,pricemethod,sale_kinds,parent_kinds,sale_category,parent_category,sale_special,parent_special,stat_code,paymentid,fit_paymentid,payflag,itemid,autocdflag,otherflag,complimentary_flag,modifier,reason,kitchen_type,seat_no,is_meal,is_backup,meal_id,meal_type,is_inv,is_addtion,club_id,holidaymethod,clubcode,sttime,endtime,fcount_hh,fcount_mm,fcditemno,Fpcno,fclub,fEntityNo,fit_saleid,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,xh,dzxh,dj_cb,je_cb,bm_ck,is_check,walkcust_ftype,keyno,memno,Fremark,deposit,fcusttdno,fbillNosub,disccode,spandhyacc,ch_printflag,accuserid,fdayandhousr,fmpdaycount,zbcardno,v_artno,Fmp_m_id,acc_clubkinds1,acc_clubkinds2,acc_clubkinds3,fcustno FROM DELETED;";
        string tableName = "pos_sales";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //pos_bills代码

    #region ※8 pos_bills_financial_method
    [SqlTrigger(Name = @"pos_bills_financial_method", Target = "[dbo].[pos_bills]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void pos_bills_financial_method()
    {
        string insertedSql = @"select billcode,billtype,rec_status,bill_status,pay_status,billshop,saleshop,payshop,billdate,opentime,closedate,closetime,openuserid,closeuserid,dailysno,tableno,tableno_ext,noofguest,serverno,periodno,shiftno,closeshift,parentshop,grand_billcode,checkin_id,cardno,memno,memid,guest_identity,name,sex,billtotal,discountpercent,discounttotal,gratuitypercent,gratuitytotal,taxpercent,taxtotal,tipstotal,rebatetotal,totalpayable,paymethod,paydesp,printno,invoiceno,invoiceflag,generateflag,payflag,reception,saletype,lockstatus,sttime,endtime,fcount_hh,fcount_mm,fcditemno,otherstatus,club_id,memsid,sequence,keyno,modify,modifytime,clubcode,Fpcno,fclub,fEntityNo,ch_payno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,is_check,bm_ck,dzxh,checker,rq_check,cardbalance,zb_bm_ck,depositall,fcusttdno,syscode,f_paykind,fRemark,saleid,paycode,accuserid,fbillnohbaccno,fhbbillflash,fRemarkdoc,quitydje,ydallje,fydbillno,finmpyj,fcustno,facctypeset FROM INSERTED;";
        string deletedSql = @"select billcode,billtype,rec_status,bill_status,pay_status,billshop,saleshop,payshop,billdate,opentime,closedate,closetime,openuserid,closeuserid,dailysno,tableno,tableno_ext,noofguest,serverno,periodno,shiftno,closeshift,parentshop,grand_billcode,checkin_id,cardno,memno,memid,guest_identity,name,sex,billtotal,discountpercent,discounttotal,gratuitypercent,gratuitytotal,taxpercent,taxtotal,tipstotal,rebatetotal,totalpayable,paymethod,paydesp,printno,invoiceno,invoiceflag,generateflag,payflag,reception,saletype,lockstatus,sttime,endtime,fcount_hh,fcount_mm,fcditemno,otherstatus,club_id,memsid,sequence,keyno,modify,modifytime,clubcode,Fpcno,fclub,fEntityNo,ch_payno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,is_check,bm_ck,dzxh,checker,rq_check,cardbalance,zb_bm_ck,depositall,fcusttdno,syscode,f_paykind,fRemark,saleid,paycode,accuserid,fbillnohbaccno,fhbbillflash,fRemarkdoc,quitydje,ydallje,fydbillno,finmpyj,fcustno,facctypeset FROM DELETED;";
        string tableName = "pos_bills";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //fitness_cardchange代码

    #region ※9 fitness_cardchange_financial_method
    [SqlTrigger(Name = @"fitness_cardchange_financial_method", Target = "[dbo].[fitness_cardchange]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void fitness_cardchange_financial_method()
    {
        string insertedSql = @"select sid,cardno,name,memkind,startdate,enddate,newcardno,newname,newmemkind,newstartdate,newenddate,total,paydate,usercode,optime,status,memo,memid,memstatus,memstatusnew,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,item,price,sale_name,itemsno FROM INSERTED;";
        string deletedSql = @"select sid,cardno,name,memkind,startdate,enddate,newcardno,newname,newmemkind,newstartdate,newenddate,total,paydate,usercode,optime,status,memo,memid,memstatus,memstatusnew,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,item,price,sale_name,itemsno FROM DELETED;";
        string tableName = "fitness_cardchange";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //jxc_bm_ck代码

    #region ※10 jxc_bm_ck_financial_method
    [SqlTrigger(Name = @"jxc_bm_ck_financial_method", Target = "[dbo].[jxc_bm_ck]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_bm_ck_financial_method()
    {
        string insertedSql = @"select bm,mc,jjff,js,bm_1,bm_2,bm_3,bm_4,bm_5,bm_6,other,bz,n_last,fNo,fdescription,fentityNo,faddress,ftelephone,fcountrycode,fterritorycode,fDeptNo,FContactor,pcno,fcreatedate,fmodifydate,fUserNo,ifdown,FClub,Fpcno,fifczzb,fiffskc FROM INSERTED;";
        string deletedSql = @"select bm,mc,jjff,js,bm_1,bm_2,bm_3,bm_4,bm_5,bm_6,other,bz,n_last,fNo,fdescription,fentityNo,faddress,ftelephone,fcountrycode,fterritorycode,fDeptNo,FContactor,pcno,fcreatedate,fmodifydate,fUserNo,ifdown,FClub,Fpcno,fifczzb,fiffskc FROM DELETED;";
        string tableName = "jxc_bm_ck";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //memcardlog代码

    #region ※11 memcardlog_financial_method
    [SqlTrigger(Name = @"memcardlog_financial_method", Target = "[dbo].[memcardlog]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void memcardlog_financial_method()
    {
        string insertedSql = @"select sid,cardno,name,memid,subclub,workshop,type,total,totalbalance,timeitem,time,timebalance,logdate,usercode,usertime,memo,timesid,present,billcode,price,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,otype,outin,cardbalancezs,facctype,rec_status,fisnew,sale_name,fifhyxy,cardbalancesp FROM INSERTED;";
        string deletedSql = @"select sid,cardno,name,memid,subclub,workshop,type,total,totalbalance,timeitem,time,timebalance,logdate,usercode,usertime,memo,timesid,present,billcode,price,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,otype,outin,cardbalancezs,facctype,rec_status,fisnew,sale_name,fifhyxy,cardbalancesp FROM DELETED;";
        string tableName = "memcardlog";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //mem_member代码

    #region ※12 mem_member_financial_method
    [SqlTrigger(Name = @"mem_member_financial_method", Target = "[dbo].[mem_member]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void mem_member_financial_method()
    {
        string insertedSql = @"select m_id,tickh,mem_id,m_id_type,mem_iden,card_ext,namee,namec,nameelast,q_id,main_id,first_mid,cardhold,if_hide,sortorder,familys,nominee,company_buy,no_name,order_text,picture,user_id,user_time,sex,passport,id,birthday,birth_zone,titlec,titlee,nation,memberkind,status,mem_period,club_id,pin_id,certification,data_input,autho_indate,autho_name,joindate,introdu_iden,introducer,introdu_memid,sale_name,issue_date,if_closedate,closedate,status_date,mem_password,iccard_no,issue_card,autho_date,autho_type,autho_id,autho_no,check_no,bank_name,tel,fax,mobilphone,address,co_tel,co_fax,co_address,co_poscode,pobox,certno,mailto_label,mailto,mailto_magazine,blood_type,from_country,from_zone,from_city,stay_country,stay_zone,stay_city,maritus,marrydate,edu_grade,hobby,nickname,spouse,children,e_mail,postcode,car,language,home_page,park,park_no,native_place,master_language,race,link_no,co_namec,co_namee,co_departmemt,co_position,co_prof,co_beeper,co_mobil,co_prop,office,salary,co_office,incomes,company_no,found_date,company_trade,company_scale,company_depute,company_follows,business_prop,register_no,billtocard,rights,credit_limit,money_id,co_enterfee,co_security,co_enterpaydate,security,co_enterendate,co_periods,co_paiedperiods,co_paiedamt,startmonthdate,endmonthdate,mfee_money,monthfee,mthyr,renderway,mfee_paiedamt,call_times,mem_paytype,mem_owes,open_bank,open_office,open_company,open_billno,open_credit,open_creditno,open_endate,remark,pos_tips,pos_tips_type,spare_no1,spare_no2,packet_no,lease_endate,hcap_refer,hcap,consum_amts,consum_times,user_content,relative,term,beeper,account_tips,reminder,zone,city,card_date,spell,co_countrycat,co_postcode,co_attn,co_rep,coupon,title,expiry_date,renewed_date,cancelled_date,handledby,application,co_attn_2,other_address,other_postcode,other_attn,other_tel,other_address2,other_postcode2,other_attn2,other_tel2,houseid,housebank,paytimelimit,housetype,housemoneytype,housesalemoney,buytime,yearperiod,posjustify,wherefrom,cohap,trytimes,ballbagnum,othername,tcredit_limit,mcredit_limit,dqcs,jrcs,source,homeaddr,hometel,homepostcode,modify,modifytime,contactperiod,contactway,linkman,site,linktime,recommend,introdusid,cardsno,cardbalance,signertype,couponno,coupontype,couponpay,depositcard,fEntityNo,ifdown,setautoid,Web_UType,FClub,Fpcno,specialflag,fbillNo,fhyinmpno,ftickh,statusinout,fpowerdoor,fifygmp,factive,fvisibleacc,factivedate,jecountall,fyjje,mem_password1,cardbalancezs,fgzjeall,spcdxhje,Fstatustype,fnewhyje,factdate,fstudentno,ifhyyjje FROM INSERTED;";
        string deletedSql = @"select m_id,tickh,mem_id,m_id_type,mem_iden,card_ext,namee,namec,nameelast,q_id,main_id,first_mid,cardhold,if_hide,sortorder,familys,nominee,company_buy,no_name,order_text,picture,user_id,user_time,sex,passport,id,birthday,birth_zone,titlec,titlee,nation,memberkind,status,mem_period,club_id,pin_id,certification,data_input,autho_indate,autho_name,joindate,introdu_iden,introducer,introdu_memid,sale_name,issue_date,if_closedate,closedate,status_date,mem_password,iccard_no,issue_card,autho_date,autho_type,autho_id,autho_no,check_no,bank_name,tel,fax,mobilphone,address,co_tel,co_fax,co_address,co_poscode,pobox,certno,mailto_label,mailto,mailto_magazine,blood_type,from_country,from_zone,from_city,stay_country,stay_zone,stay_city,maritus,marrydate,edu_grade,hobby,nickname,spouse,children,e_mail,postcode,car,language,home_page,park,park_no,native_place,master_language,race,link_no,co_namec,co_namee,co_departmemt,co_position,co_prof,co_beeper,co_mobil,co_prop,office,salary,co_office,incomes,company_no,found_date,company_trade,company_scale,company_depute,company_follows,business_prop,register_no,billtocard,rights,credit_limit,money_id,co_enterfee,co_security,co_enterpaydate,security,co_enterendate,co_periods,co_paiedperiods,co_paiedamt,startmonthdate,endmonthdate,mfee_money,monthfee,mthyr,renderway,mfee_paiedamt,call_times,mem_paytype,mem_owes,open_bank,open_office,open_company,open_billno,open_credit,open_creditno,open_endate,remark,pos_tips,pos_tips_type,spare_no1,spare_no2,packet_no,lease_endate,hcap_refer,hcap,consum_amts,consum_times,user_content,relative,term,beeper,account_tips,reminder,zone,city,card_date,spell,co_countrycat,co_postcode,co_attn,co_rep,coupon,title,expiry_date,renewed_date,cancelled_date,handledby,application,co_attn_2,other_address,other_postcode,other_attn,other_tel,other_address2,other_postcode2,other_attn2,other_tel2,houseid,housebank,paytimelimit,housetype,housemoneytype,housesalemoney,buytime,yearperiod,posjustify,wherefrom,cohap,trytimes,ballbagnum,othername,tcredit_limit,mcredit_limit,dqcs,jrcs,source,homeaddr,hometel,homepostcode,modify,modifytime,contactperiod,contactway,linkman,site,linktime,recommend,introdusid,cardsno,cardbalance,signertype,couponno,coupontype,couponpay,depositcard,fEntityNo,ifdown,setautoid,Web_UType,FClub,Fpcno,specialflag,fbillNo,fhyinmpno,ftickh,statusinout,fpowerdoor,fifygmp,factive,fvisibleacc,factivedate,jecountall,fyjje,mem_password1,cardbalancezs,fgzjeall,spcdxhje,Fstatustype,fnewhyje,factdate,fstudentno,ifhyyjje FROM DELETED;";
        string tableName = "mem_member";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //fitness_enroll_qchange代码

    #region ※13 fitness_enroll_qchange_financial_method
    [SqlTrigger(Name = @"fitness_enroll_qchange_financial_method", Target = "[dbo].[fitness_enroll_qchange]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void fitness_enroll_qchange_financial_method()
    {
        string insertedSql = @"select sid,class,cardno,cname,tel,company_tel,enroll_date,start_date,end_date,operator,op_time,status,memid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fkscs,fincs,tptcs,fpricexh,fyxday,kssj,fmp,fptmp,coach,lscard,sttime,endtime,psrs,pshours,fdiscount,fdiscountje,fbmje,fdcset,fdctomonthset,fbmhyje,checkczr,checkrq,fkcclose,fifcheck,stu_q_id,fdctprice,foldclass,fwwkcje,fnewkcallje,folddjprice,fartjlno,fartjlnoold,fstudentno,freturnje,fifysje,fkcdown,kccodena,totalpro,discountpercent,fsycss,sale_name,fparentclass,fnesscouqry,fkcpriceje,fenroquitqry,fpmclatype,faccpay,fneworadd FROM INSERTED;";
        string deletedSql = @"select sid,class,cardno,cname,tel,company_tel,enroll_date,start_date,end_date,operator,op_time,status,memid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fkscs,fincs,tptcs,fpricexh,fyxday,kssj,fmp,fptmp,coach,lscard,sttime,endtime,psrs,pshours,fdiscount,fdiscountje,fbmje,fdcset,fdctomonthset,fbmhyje,checkczr,checkrq,fkcclose,fifcheck,stu_q_id,fdctprice,foldclass,fwwkcje,fnewkcallje,folddjprice,fartjlno,fartjlnoold,fstudentno,freturnje,fifysje,fkcdown,kccodena,totalpro,discountpercent,fsycss,sale_name,fparentclass,fnesscouqry,fkcpriceje,fenroquitqry,fpmclatype,faccpay,fneworadd FROM DELETED;";
        string tableName = "fitness_enroll_qchange";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //sys_identity代码

    #region ※14 sys_identity_financial_method
    [SqlTrigger(Name = @"sys_identity_financial_method", Target = "[dbo].[sys_identity]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void sys_identity_financial_method()
    {
        string insertedSql = @"select code,name_c,name_e,if_group_type,list_order,link_card,display_color,court_fee,remark,identity_type,parent_code,nfree_hours,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,monthswcs,fmpno,week1,week2,week3,week4,week5,week6,week7,ifshdoorpay FROM INSERTED;";
        string deletedSql = @"select code,name_c,name_e,if_group_type,list_order,link_card,display_color,court_fee,remark,identity_type,parent_code,nfree_hours,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,monthswcs,fmpno,week1,week2,week3,week4,week5,week6,week7,ifshdoorpay FROM DELETED;";
        string tableName = "sys_identity";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //fitness_classes代码

    #region ※15 fitness_classes_financial_method
    [SqlTrigger(Name = @"fitness_classes_financial_method", Target = "[dbo].[fitness_classes]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void fitness_classes_financial_method()
    {
        string insertedSql = @"select code,cname,instructor,capacity,start_date,end_date,color,minimal,venueid,ctype,status,remarks,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fkscs,fifmp,fincs,fifptyesno,tptcs,fpricexh,fyxday,kssj,frsprice,fmp,fptmp,fifhxjlset,fhousers,classtype,classjb,fkcprice,fzdrs,fzgrs,remark,fdiscount,fdiscountje,fyskscs,tysptcs,f_zdshtime,openuserid,fparentclass,fpmclatype FROM INSERTED;";
        string deletedSql = @"select code,cname,instructor,capacity,start_date,end_date,color,minimal,venueid,ctype,status,remarks,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fkscs,fifmp,fincs,fifptyesno,tptcs,fpricexh,fyxday,kssj,frsprice,fmp,fptmp,fifhxjlset,fhousers,classtype,classjb,fkcprice,fzdrs,fzgrs,remark,fdiscount,fdiscountje,fyskscs,tysptcs,f_zdshtime,openuserid,fparentclass,fpmclatype FROM DELETED;";
        string tableName = "fitness_classes";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //mem_kind代码

    #region ※16 mem_kind_financial_method
    [SqlTrigger(Name = @"mem_kind_financial_method", Target = "[dbo].[mem_kind]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void mem_kind_financial_method()
    {
        string insertedSql = @"select memberkind,name,code,memo,enfee,f_no,trans,enf_kind,begin_date,num_of_cards,if_statistic,if_normal_rpt,checkin_identity,monthfee_code,paymonthfee,directpos,holidaylimit,depositcard,icno,jifenxu,zhekou,yflx,zdjf,csadd,ifyxq,ifxhjf,shje,jfs,ifdown,pcno,ifsph,fEntityNo,f_xhcs,f_cd,f_in_pass,f_if_pass,f_view_pass,f_is_icje,f_ck_bsy,f_ck_bdy,f_hy_len,f_xhje,f_dayje,f_daycs,f_yxjehs,hpric,sttime,endtime,ifdcje,ifdcflash,kdjea,kdcsa,iflskh,hygps,hyyxqday,f_daytime,fcreatedate,fmodifydate,fDeptNo,fUserNo,n_last,ifnewdate,sortid,ifuse,client,fifyhgh,fyhdate,fifmasic,fzyzbsl,finje,fifxhjhs,ifoutckje,ifhyicacc,fyjje,ifmonthje,iftipkd,ifjjrkc,ifdcpass,ifstuclass,ifActive,ifokin,ifinkc,ifinks,display_color,ifshoesyn,ifdoorok,z1,z2,z3,z4,z5,z6,z7,fqry,ifhyiccount,factive,fshjetip,ficje,fifhyxh,rz1,rz2,rz3,rz4,rz5,rz6,rz7,ifnotxhsp,fydlook,ftdflashn,fonesl,fvisibleacc,dymp,acc_code,fhyknotacc,fmzje,hymkzs,ifdaytime,daytime,fyxrqset,FClub,Fpcno,z8,ifinsmtimese,fjzrp,fifxhbalance,fjfset,fpayje,fpayjejh,hystatus,statuslock,ackdoor,spjexhset,xhspset,Fstatustype,fdefmonthje,fbkjeset,flockcz,fdoormp,fdiscmp,fiflyzbset,discountpercent,othercs,fzsdays,fhyall,Fkindhy,acc_clubkinds3,fhykkdays,ifstartset,item_xhcs,SaleForInternet,description FROM INSERTED;";
        string deletedSql = @"select memberkind,name,code,memo,enfee,f_no,trans,enf_kind,begin_date,num_of_cards,if_statistic,if_normal_rpt,checkin_identity,monthfee_code,paymonthfee,directpos,holidaylimit,depositcard,icno,jifenxu,zhekou,yflx,zdjf,csadd,ifyxq,ifxhjf,shje,jfs,ifdown,pcno,ifsph,fEntityNo,f_xhcs,f_cd,f_in_pass,f_if_pass,f_view_pass,f_is_icje,f_ck_bsy,f_ck_bdy,f_hy_len,f_xhje,f_dayje,f_daycs,f_yxjehs,hpric,sttime,endtime,ifdcje,ifdcflash,kdjea,kdcsa,iflskh,hygps,hyyxqday,f_daytime,fcreatedate,fmodifydate,fDeptNo,fUserNo,n_last,ifnewdate,sortid,ifuse,client,fifyhgh,fyhdate,fifmasic,fzyzbsl,finje,fifxhjhs,ifoutckje,ifhyicacc,fyjje,ifmonthje,iftipkd,ifjjrkc,ifdcpass,ifstuclass,ifActive,ifokin,ifinkc,ifinks,display_color,ifshoesyn,ifdoorok,z1,z2,z3,z4,z5,z6,z7,fqry,ifhyiccount,factive,fshjetip,ficje,fifhyxh,rz1,rz2,rz3,rz4,rz5,rz6,rz7,ifnotxhsp,fydlook,ftdflashn,fonesl,fvisibleacc,dymp,acc_code,fhyknotacc,fmzje,hymkzs,ifdaytime,daytime,fyxrqset,FClub,Fpcno,z8,ifinsmtimese,fjzrp,fifxhbalance,fjfset,fpayje,fpayjejh,hystatus,statuslock,ackdoor,spjexhset,xhspset,Fstatustype,fdefmonthje,fbkjeset,flockcz,fdoormp,fdiscmp,fiflyzbset,discountpercent,othercs,fzsdays,fhyall,Fkindhy,acc_clubkinds3,fhykkdays,ifstartset,item_xhcs,SaleForInternet,description FROM DELETED;";
        string tableName = "mem_kind";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //SnArt代码

    #region ※17 SnArt_financial_method
    [SqlTrigger(Name = @"SnArt_financial_method", Target = "[dbo].[SnArt]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void SnArt_financial_method()
    {
        string insertedSql = @"select v_artNo,v_name1,v_name2,i_age,v_sex,i_height,i_weight,v_tel,v_home,v_address,v_artModeNo,v_groupNo,v_areaNo,v_spec,i_called,dt_checkIn,dt_checkOut,i_tagTurn,v_onDuty,i_status,i_downstatus,i_order,v_stopstatus,i_seqNo,i_seqBaseNo,i_adjustNo,dt_down,v_memo,Bz,CardCode,iscard,i_lastseqno,i_dateflag,i_qjflag,v_LayerNo,fretailprice,counttype,fPartNo,tickh,picture,fdoormp,fbillno,fiftest,fspbm,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,stdatetime,enddatetime,cardsno,mem_id,q_id,g_photo FROM INSERTED;";
        string deletedSql = @"select v_artNo,v_name1,v_name2,i_age,v_sex,i_height,i_weight,v_tel,v_home,v_address,v_artModeNo,v_groupNo,v_areaNo,v_spec,i_called,dt_checkIn,dt_checkOut,i_tagTurn,v_onDuty,i_status,i_downstatus,i_order,v_stopstatus,i_seqNo,i_seqBaseNo,i_adjustNo,dt_down,v_memo,Bz,CardCode,iscard,i_lastseqno,i_dateflag,i_qjflag,v_LayerNo,fretailprice,counttype,fPartNo,tickh,picture,fdoormp,fbillno,fiftest,fspbm,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,stdatetime,enddatetime,cardsno,mem_id,q_id,g_photo FROM DELETED;";
        string tableName = "SnArt";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //gym_reserve代码

    #region ※18 gym_reserve_financial_method
    [SqlTrigger(Name = @"gym_reserve_financial_method", Target = "[dbo].[gym_reserve]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void gym_reserve_financial_method()
    {
        string insertedSql = @"select sid,res_date,time_mode,period_id,res_time,res_item,cardno,cname,picture,operator,op_time,status,status1,groups,person,color,memo,if_present,memid,fEntityNo,FClub,Fpcno,ifdown,statusacc,dcbillcode,mobilphone,begin_date,end_date,bill_code,new_timestamp,begin_datetime,end_datetime FROM INSERTED;";
        string deletedSql = @"select sid,res_date,time_mode,period_id,res_time,res_item,cardno,cname,picture,operator,op_time,status,status1,groups,person,color,memo,if_present,memid,fEntityNo,FClub,Fpcno,ifdown,statusacc,dcbillcode,mobilphone,begin_date,end_date,bill_code,new_timestamp,begin_datetime,end_datetime FROM DELETED;";
        string tableName = "gym_reserve";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //fitness_enroll代码

    #region ※19 fitness_enroll_financial_method
    [SqlTrigger(Name = @"fitness_enroll_financial_method", Target = "[dbo].[fitness_enroll]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void fitness_enroll_financial_method()
    {
        string insertedSql = @"select sid,class,cardno,cname,tel,company_tel,enroll_date,start_date,end_date,operator,op_time,status,memid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fkscs,fincs,tptcs,fpricexh,fyxday,kssj,fmp,fptmp,coach,lscard,sttime,endtime,psrs,pshours,fdiscount,fdiscountje,fbmje,fdcset,fdctomonthset,fbmhyje,checkczr,checkrq,fkcclose,fifcheck,stu_q_id,fdctprice,foldclass,fwwkcje,fnewkcallje,folddjprice,fartjlno,fartjlnoold,fstudentno,freturnje,fifysje,fkcdown,kccodena,totalpro,discountpercent,fsycss,sale_name,fparentclass,fnesscouqry,fkcpriceje,fenroquitqry,fpmclatype,faccpay,fneworadd,fbcsh FROM INSERTED;";
        string deletedSql = @"select sid,class,cardno,cname,tel,company_tel,enroll_date,start_date,end_date,operator,op_time,status,memid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fkscs,fincs,tptcs,fpricexh,fyxday,kssj,fmp,fptmp,coach,lscard,sttime,endtime,psrs,pshours,fdiscount,fdiscountje,fbmje,fdcset,fdctomonthset,fbmhyje,checkczr,checkrq,fkcclose,fifcheck,stu_q_id,fdctprice,foldclass,fwwkcje,fnewkcallje,folddjprice,fartjlno,fartjlnoold,fstudentno,freturnje,fifysje,fkcdown,kccodena,totalpro,discountpercent,fsycss,sale_name,fparentclass,fnesscouqry,fkcpriceje,fenroquitqry,fpmclatype,faccpay,fneworadd,fbcsh FROM DELETED;";
        string tableName = "fitness_enroll";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //gym_period代码

    #region ※20 gym_period_financial_method
    [SqlTrigger(Name = @"gym_period_financial_method", Target = "[dbo].[gym_period]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void gym_period_financial_method()
    {
        string insertedSql = @"select sid,time_mode,start_date,end_date,sequence,period,memo,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM INSERTED;";
        string deletedSql = @"select sid,time_mode,start_date,end_date,sequence,period,memo,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM DELETED;";
        string tableName = "gym_period";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //t_fsl_sk_student05代码

    #region ※21 t_fsl_sk_student05_financial_method
    [SqlTrigger(Name = @"t_fsl_sk_student05_financial_method", Target = "[dbo].[t_fsl_sk_student05]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void t_fsl_sk_student05_financial_method()
    {
        string insertedSql = @"select v_artModeNo,i_minuteOne,n_priceOne,i_minuteTwo,n_priceTwo,i_minuteThree,n_priceThree,n_FeeOne,n_FeeTwo,n_FeeThree,v_LayerNo,n_PriceDian,n_FeeDian,n_FeeAdd,n_FeeAddAdd,n_FeeAddDian,ftype,pcno,fEntityNo,kscs,kssj,fw1,fw2,fw3,fw4,fw5,fw6,fw7,fifmp,v_bcname,yflx,fifpt1,tptcs,fpartno,v_name1,fbillNo,todayrq,todayrq1,v_name2,kh,ftypeic,fretailprice,fretailprice1,fspecification,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fReturnedQty,fbcsh,fsycs,fbbjlman,fkczlall,fkcpriceje FROM INSERTED;";
        string deletedSql = @"select v_artModeNo,i_minuteOne,n_priceOne,i_minuteTwo,n_priceTwo,i_minuteThree,n_priceThree,n_FeeOne,n_FeeTwo,n_FeeThree,v_LayerNo,n_PriceDian,n_FeeDian,n_FeeAdd,n_FeeAddAdd,n_FeeAddDian,ftype,pcno,fEntityNo,kscs,kssj,fw1,fw2,fw3,fw4,fw5,fw6,fw7,fifmp,v_bcname,yflx,fifpt1,tptcs,fpartno,v_name1,fbillNo,todayrq,todayrq1,v_name2,kh,ftypeic,fretailprice,fretailprice1,fspecification,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fReturnedQty,fbcsh,fsycs,fbbjlman,fkczlall,fkcpriceje FROM DELETED;";
        string tableName = "t_fsl_sk_student05";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //gym_item代码

    #region ※22 gym_item_financial_method
    [SqlTrigger(Name = @"gym_item_financial_method", Target = "[dbo].[gym_item]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void gym_item_financial_method()
    {
        string insertedSql = @"select item_code,item_name,max_groups,max_persons,sequence,time_mode,cname_class,ch_temp,int_id,ch_areano,int_person,fbillNo,ch_lockflag,dt_opertime,fbmp1,fbmp2,ch_kind,t_ifstart,fEntityNo,Fpcno,FClub,n_last,ifdown,status,checkin_id,Web_ItemType,fcreatedate,fmodifydate,fUserNo,ticket_code,userlock,fdkoff,fdkon,fifdg,fifdkline,dkonofftype,Project_code,ftiptime,ftipclecd,dt_closetime,fkcyacc,fyjje,seal,m_id FROM INSERTED;";
        string deletedSql = @"select item_code,item_name,max_groups,max_persons,sequence,time_mode,cname_class,ch_temp,int_id,ch_areano,int_person,fbillNo,ch_lockflag,dt_opertime,fbmp1,fbmp2,ch_kind,t_ifstart,fEntityNo,Fpcno,FClub,n_last,ifdown,status,checkin_id,Web_ItemType,fcreatedate,fmodifydate,fUserNo,ticket_code,userlock,fdkoff,fdkon,fifdg,fifdkline,dkonofftype,Project_code,ftiptime,ftipclecd,dt_closetime,fkcyacc,fyjje,seal,m_id FROM DELETED;";
        string tableName = "gym_item";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //fitness_monthfee代码

    #region ※23 fitness_monthfee_financial_method
    [SqlTrigger(Name = @"fitness_monthfee_financial_method", Target = "[dbo].[fitness_monthfee]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void fitness_monthfee_financial_method()
    {
        string insertedSql = @"select sid,cardno,name,paydate,months,monthfee,startdate,enddate,total,billcode,usercode,optime,memo,memid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,item,price,sale_name FROM INSERTED;";
        string deletedSql = @"select sid,cardno,name,paydate,months,monthfee,startdate,enddate,total,billcode,usercode,optime,memo,memid,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,item,price,sale_name FROM DELETED;";
        string tableName = "fitness_monthfee";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //gym_kind代码

    #region ※24 gym_kind_financial_method
    [SqlTrigger(Name = @"gym_kind_financial_method", Target = "[dbo].[gym_kind]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void gym_kind_financial_method()
    {
        string insertedSql = @"select code,cname,cdsl,t_ifstart,t_ifrsacc,zgxf,zdxf,ifxacc,if_tstime,ifmmhh,ifstarhh,f_ts_time,f_zdshtime,f_ckjs,fifdg,ifnotdc,ifnothy,fmodisttime,fmodiendtime,fifoffdk,fifautoqc,display_color,kcdisplay_color,yesjs,yjsje,nothycolor,hycolor,cqcolor,bccolor,addhyh,addname,addtel,dcdelcolor,fzdxhtime,fifhyxh,fEntityNo,FClub,Fpcno,n_last,ifdown,fviewbmp,shop_code,ticket_code,fcreatedate,fmodifydate,fUserNo,Web_ItemType,Web_IsShow,Project_code,acc_clubkinds3,foffdktimemin,fifcdsloff,fifdayhouse,fkcendtimeset,fgridset,fviewset,fkcjemin,fkcnotjemin,seal,fydopencd,delcdtime FROM INSERTED;";
        string deletedSql = @"select code,cname,cdsl,t_ifstart,t_ifrsacc,zgxf,zdxf,ifxacc,if_tstime,ifmmhh,ifstarhh,f_ts_time,f_zdshtime,f_ckjs,fifdg,ifnotdc,ifnothy,fmodisttime,fmodiendtime,fifoffdk,fifautoqc,display_color,kcdisplay_color,yesjs,yjsje,nothycolor,hycolor,cqcolor,bccolor,addhyh,addname,addtel,dcdelcolor,fzdxhtime,fifhyxh,fEntityNo,FClub,Fpcno,n_last,ifdown,fviewbmp,shop_code,ticket_code,fcreatedate,fmodifydate,fUserNo,Web_ItemType,Web_IsShow,Project_code,acc_clubkinds3,foffdktimemin,fifcdsloff,fifdayhouse,fkcendtimeset,fgridset,fviewset,fkcjemin,fkcnotjemin,seal,fydopencd,delcdtime FROM DELETED;";
        string tableName = "gym_kind";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //jxc_dj_kc_2代码

    #region ※25 jxc_dj_kc_2_financial_method
    [SqlTrigger(Name = @"jxc_dj_kc_2_financial_method", Target = "[dbo].[jxc_dj_kc_2]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_dj_kc_2_financial_method()
    {
        string insertedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,je,is_check,sl_kc,dj_cb,je_cb,dzxh,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,slsl,sjsl FROM INSERTED;";
        string deletedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,je,is_check,sl_kc,dj_cb,je_cb,dzxh,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,slsl,sjsl FROM DELETED;";
        string tableName = "jxc_dj_kc_2";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //jxc_dj_kc_zc_2代码

    #region ※26 jxc_dj_kc_zc_2_financial_method
    [SqlTrigger(Name = @"jxc_dj_kc_zc_2_financial_method", Target = "[dbo].[jxc_dj_kc_zc_2]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_dj_kc_zc_2_financial_method()
    {
        string insertedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,je,dj_cb,je_cb,dzxh,is_check,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM INSERTED;";
        string deletedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,je,dj_cb,je_cb,dzxh,is_check,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM DELETED;";
        string tableName = "jxc_dj_kc_zc_2";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //jxc_dj_kc_db_2代码

    #region ※27 jxc_dj_kc_db_2_financial_method
    [SqlTrigger(Name = @"jxc_dj_kc_db_2_financial_method", Target = "[dbo].[jxc_dj_kc_db_2]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_dj_kc_db_2_financial_method()
    {
        string insertedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,bm_ck1,yyyymmdd,jxc_yyyymm,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj_dc,dj_dc_f,je_dc,dj_dr,dj_dr_f,je_dr,je_ce,is_check,sl_kc,dzxh,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,slsl,sjsl FROM INSERTED;";
        string deletedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,bm_ck1,yyyymmdd,jxc_yyyymm,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj_dc,dj_dc_f,je_dc,dj_dr,dj_dr_f,je_dr,je_ce,is_check,sl_kc,dzxh,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,slsl,sjsl FROM DELETED;";
        string tableName = "jxc_dj_kc_db_2";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //jxc_dj_xs_2代码

    #region ※28 jxc_dj_xs_2_financial_method
    [SqlTrigger(Name = @"jxc_dj_xs_2_financial_method", Target = "[dbo].[jxc_dj_xs_2]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_dj_xs_2_financial_method()
    {
        string insertedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_dw,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,dj_hs,dj_hs_f,dj_cb,je_cb,zk,zk_je,slv,se,je,je_hs,bs_xs_th,dh_dd,dh_th,sl_th,is_check,dzxh,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM INSERTED;";
        string deletedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_dw,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,dj_hs,dj_hs_f,dj_cb,je_cb,zk,zk_je,slv,se,je,je_hs,bs_xs_th,dh_dd,dh_th,sl_th,is_check,dzxh,bz,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM DELETED;";
        string tableName = "jxc_dj_xs_2";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //jxc_dj_gh_2代码

    #region ※29 jxc_dj_gh_2_financial_method
    [SqlTrigger(Name = @"jxc_dj_gh_2_financial_method", Target = "[dbo].[jxc_dj_gh_2]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_dj_gh_2_financial_method()
    {
        string insertedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_dw,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,dj_hs,dj_hs_f,dj_cb,je_cb,zk,zk_je,slv,se,je,je_hs,bs_gh_th,dh_dd,dh_th,sl_th,is_check,dzxh,bz,dh_dd_xh,dj_ls,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM INSERTED;";
        string deletedSql = @"select dh,bm_gsjg,xh,bm_sp,bm_djlx,bm_ck,yyyymmdd,jxc_yyyymm,bm_dw,bm_jbr,bm_bm,dw,dw_f,zhl,sl,sl_f,dj,dj_f,dj_hs,dj_hs_f,dj_cb,je_cb,zk,zk_je,slv,se,je,je_hs,bs_gh_th,dh_dd,dh_th,sl_th,is_check,dzxh,bz,dh_dd_xh,dj_ls,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM DELETED;";
        string tableName = "jxc_dj_gh_2";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //v_jxc_zb_sp_kc_all代码

    #region ※30 v_jxc_zb_sp_kc_all_financial_method 视图废除
    //[SqlTrigger(Name = @"v_jxc_zb_sp_kc_all_financial_method", Target = "[dbo].[v_jxc_zb_sp_kc_all]", Event = "FOR INSERT, UPDATE, DELETE")]
    //public static void v_jxc_zb_sp_kc_all_financial_method()
    //{
    //    string insertedSql = @"select jxc_yyyymm,bm_gsjg,bm_ck,bm_sp,sl_qc,je_qc,sl_in,je_in,sl_out,je_out,sl_qm,je_qm,dj_cb,sl_qm_pd FROM INSERTED;";
    //    string deletedSql = @"select jxc_yyyymm,bm_gsjg,bm_ck,bm_sp,sl_qc,je_qc,sl_in,je_in,sl_out,je_out,sl_qm,je_qm,dj_cb,sl_qm_pd FROM DELETED;";
    //    string tableName = "v_jxc_zb_sp_kc_all";
    //    string timeStampColName = "null";
    //    syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    //}
    #endregion

    //jxc_bm_sp代码

    #region ※31 jxc_bm_sp_financial_method
    [SqlTrigger(Name = @"jxc_bm_sp_financial_method", Target = "[dbo].[jxc_bm_sp]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_bm_sp_financial_method()
    {
        string insertedSql = @"select bm,bm_lb,mc,gg,barcode,dw,dw_d,dw_x,zhl_d,zhl_x,zjm,cd,bm_gys,dj_jh,dj_ls,dj_ls_d,dj_ls_x,dj_pf,dj_pf_d,dj_pf_x,dj_pf1,dj_pf2,dj_pf3,dj_pf4,dj_hy,dj_hy_d,dj_hy_x,dj_max,dj_min,rq_new,rq_edit,ly_edit,is_stop,bz,spsx,lb,is_tjsp,n_last,kcfs,fEntityNo,pcno,fcreatedate,fmodifydate,fDeptNo,fUserNo,n_last1,ifdown,FClub,Fpcno,ifservice,ifstock,ifvalid,ifdiscount,ch_printflag,vch_printer,pricemethod,fjhlps,fhylp FROM INSERTED;";
        string deletedSql = @"select bm,bm_lb,mc,gg,barcode,dw,dw_d,dw_x,zhl_d,zhl_x,zjm,cd,bm_gys,dj_jh,dj_ls,dj_ls_d,dj_ls_x,dj_pf,dj_pf_d,dj_pf_x,dj_pf1,dj_pf2,dj_pf3,dj_pf4,dj_hy,dj_hy_d,dj_hy_x,dj_max,dj_min,rq_new,rq_edit,ly_edit,is_stop,bz,spsx,lb,is_tjsp,n_last,kcfs,fEntityNo,pcno,fcreatedate,fmodifydate,fDeptNo,fUserNo,n_last1,ifdown,FClub,Fpcno,ifservice,ifstock,ifvalid,ifdiscount,ch_printflag,vch_printer,pricemethod,fjhlps,fhylp FROM DELETED;";
        string tableName = "jxc_bm_sp";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //jxc_zb_sp_kc代码

    #region ※32 jxc_zb_sp_kc_financial_method
    [SqlTrigger(Name = @"jxc_zb_sp_kc_financial_method", Target = "[dbo].[jxc_zb_sp_kc]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void jxc_zb_sp_kc_financial_method()
    {
        string insertedSql = @"select jxc_yyyymm,bm_gsjg,bm_ck,bm_sp,sl_qc,je_qc,sl_in,je_in,sl_out,je_out,sl_qm,je_qm,dj_cb,sl_qm_pd,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM INSERTED;";
        string deletedSql = @"select jxc_yyyymm,bm_gsjg,bm_ck,bm_sp,sl_qc,je_qc,sl_in,je_in,sl_out,je_out,sl_qm,je_qm,dj_cb,sl_qm_pd,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown FROM DELETED;";
        string tableName = "jxc_zb_sp_kc";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //gym_status代码

    #region ※33 gym_status_financial_method
    [SqlTrigger(Name = @"gym_status_financial_method", Target = "[dbo].[gym_status]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void gym_status_financial_method()
    {
        string insertedSql = @"select sid,start_date,end_date,period_id,item_code,time_mode,status,reason,operator,op_time,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,res_time FROM INSERTED;";
        string deletedSql = @"select sid,start_date,end_date,period_id,item_code,time_mode,status,reason,operator,op_time,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,res_time FROM DELETED;";
        string tableName = "gym_status";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //card_times_info代码

    #region ※34 card_times_info_financial_method
    [SqlTrigger(Name = @"card_times_info_financial_method", Target = "[dbo].[card_times_info]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void card_times_info_financial_method()
    {
        string insertedSql = @"select timescode,timesname,timestype,othercode,payment,parentcode,cardcode,timesno,unitamt,limitstart,limitend,remarks,timessent,amt,amtsent,validday,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fsetitemdate,fxmitems FROM INSERTED;";
        string deletedSql = @"select timescode,timesname,timestype,othercode,payment,parentcode,cardcode,timesno,unitamt,limitstart,limitend,remarks,timessent,amt,amtsent,validday,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,fsetitemdate,fxmitems FROM DELETED;";
        string tableName = "card_times_info";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //t_fsl_Entity1代码
    #region ※35 t_fsl_Entity1_financial_method
    [SqlTrigger(Name = @"t_fsl_Entity1_financial_method", Target = "[dbo].[t_fsl_Entity1]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void t_fsl_Entity1_financial_method()
    {
        string insertedSql = @"select code,fname,parentcode,ftype,fifok,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,WORKSHOP_ID,fvch_printer FROM INSERTED;";
        string deletedSql = @"select code,fname,parentcode,ftype,fifok,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,WORKSHOP_ID,fvch_printer FROM DELETED;";
        string tableName = "t_fsl_Entity1";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion

    //t_fsl_Entity2代码
    #region ※36 t_fsl_Entity2_financial_method
    [SqlTrigger(Name = @"t_fsl_Entity2_financial_method", Target = "[dbo].[t_fsl_Entity2]", Event = "FOR INSERT, UPDATE, DELETE")]
    public static void t_fsl_Entity2_financial_method()
    {
        string insertedSql = @"select code,fname,parentcode,ftype,fifok,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,WORKSHOP_ID,fvch_printer FROM INSERTED;";
        string deletedSql = @"select code,fname,parentcode,ftype,fifok,fEntityNo,FClub,Fpcno,fcreatedate,fmodifydate,fUserNo,n_last,ifdown,WORKSHOP_ID,fvch_printer FROM DELETED;";
        string tableName = "t_fsl_Entity2";
        string timeStampColName = "null";
        syncRecordToDong8(insertedSql, deletedSql, tableName, timeStampColName);
    }
    #endregion



    /// <summary>
    /// 发送json到动吧服务器
    /// </summary>
    /// <param name="insertedSql"></param>
    /// <param name="deletedSql"></param>
    /// <param name="tableName"></param>
    /// <param name="timeStampColName"></param>
    private static void syncRecordToDong8(string insertedSql, string deletedSql, string tableName, string timeStampColName)
    {
        //SqlCommand command;

        SqlTriggerContext triggContext = SqlContext.TriggerContext;
        SqlPipe pipe = SqlContext.Pipe;
        SqlDataReader insertedReader = null;

        //SqlCommand deletedCommand;
        SqlDataReader deletedReader = null;
        tongbu m = null;

        //根据传入的表实例化对象
        m = instanceObjectM(tableName, m);

        using (SqlConnection connection
            = new SqlConnection(@"context connection=true"))
        {
            if (connection.State == System.Data.ConnectionState.Closed || connection.State == System.Data.ConnectionState.Broken)
            {
                connection.Open();
            }
            string sendJs = null;
            int getReturn;

            //查询上下文是否有动吧监听工具发送的信号，如果有的话就不执行触发函数
            //不管来自云端还是本地客户端的操作全都要触发
            //if (hasContextInfo(connection))
            //{
            //    return;
            //}

            try
            {

                m.sync_id = Guid.NewGuid().ToString("D");
                m.LocalId = LocalId;
                //m.club_id = RemoteId;
                m.data_type = tableName;

                List<Dictionary<String, Object>> insertedMaps = null;
                List<Dictionary<String, Object>> deletedMaps = null;
                //saveErrLog("insertedSql = " + insertedSql + "\n\r,deletedSql=" + deletedSql, "log");
                //判断是触发什么事件，增删改？
                switch (triggContext.TriggerAction)
                {
                    case TriggerAction.Insert:
                        if (@switch == true)
                            saveErrLog("Insert" + sendJs, "log");//
                        insertedMaps = toDicts(insertedSql, connection);
                        if (insertedMaps.Count == 0)
                        {
                            return;
                        }
                        if (@switch == true)
                            saveErrLog("1. insertedMaps.size = " + insertedMaps.Count, "log");//
                        m.sync_type = 0;
                        m.fillFields(insertedMaps[0], null);//报错
                        if (@switch == true)
                            saveErrLog("fillFields" + sendJs, "log");//
                        m.fillPK(insertedMaps[0]);
                        if (@switch == true)
                            saveErrLog("fillPK" + sendJs, "log");//
                        //将对象生成json字符串
                        sendJs = m.toJson();
                        if (@switch == true)
                            saveErrLog("toJson" + sendJs, "log");
                        //处理json字符串
                        getReturn = SendAndSaveLog(tableName, connection, sendJs);
                        break;

                    case TriggerAction.Update:

                        insertedMaps = toDicts(insertedSql, connection);
                        deletedMaps = toDicts(deletedSql, connection);

                        if (insertedMaps.Count == 0 || deletedMaps.Count == 0)
                        {
                            return;
                        }

                        for (int i = 0; i < insertedMaps.Count; i++)
                        {
                            m.sync_id = Guid.NewGuid().ToString("D");
                            m.sync_type = 1;
                            m.fillFields(insertedMaps[i], deletedMaps[i]);
                            m.fillPK(deletedMaps[i]);
                            
                           m.fillTimestamp(deletedMaps[i], timeStampColName);

                            sendJs = m.toJson();
                            // saveErrLog("aaa" + sendJs, "log");
                            getReturn = SendAndSaveLog(tableName, connection, sendJs);
                        }


                        break;

                    case TriggerAction.Delete:
                        deletedMaps = toDicts(deletedSql, connection);
                        if (deletedMaps.Count == 0)
                        {
                            return;
                        }

                        foreach (var deletedMap in deletedMaps)
                        {
                            m.sync_id = Guid.NewGuid().ToString("D");
                            m.sync_type = 2;
                            m.fillPK(deletedMap);
                            m.fillTimestamp(deletedMap, timeStampColName);

                            sendJs = m.toJson();
                            //saveErrLog("aaa" + sendJs, "log");
                            getReturn = SendAndSaveLog(tableName, connection, sendJs);
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                saveErrLog(ex.Message + "\n\r" + ex.StackTrace, "ex");
                if (ex.Message.Contains("-1"))
                {
                    MyException MyEx = new MyException("返回冲突，保存失败！");
                    MyEx.ExtraErrorInfo = "修改数据库触发同步机制，动吧服务器返回了-1。请联系技术人员核对时间戳是否正确。";
                    //saveErrLog(MyEx.Message, "ex");
                    throw MyEx;
                }
                else if (ex.Message.Contains("-6"))
                {
                    MyException MyEx = new MyException("网络异常后存入t_SyncFinancialRecords失败！");
                    MyEx.ExtraErrorInfo = "发送json到动吧服务器，没有返回结果&&插入到t_SyncFinancialRecords表失败了。";
                    //saveErrLog(MyEx.Message, "ex");
                    throw MyEx;
                }
            }
            finally
            {
                if (insertedReader != null) insertedReader.Close();
                if (deletedReader != null) deletedReader.Close();
            }

        }
    }

    private static int SendAndSaveLog(string tableName, SqlConnection connection, string sendJs)
    {
        int getReturn;
        //保存发送的json
        if (@switch)
        {
            saveErrLog("[" + sendJs + "]", "log");
        }
        //执行发送json到动吧服务器的方法
        getReturn = SendToDong8Server(sendJs, tableName, connection);
        if (getReturn == -1)
        {
            //int a = Convert.ToInt32("aa");
            //如果返回值是-1，往上抛异常
            MyException m = new MyException("返回-1,冲突，请重试！");
            m.ExtraErrorInfo = "修改数据库触发同步机制，动吧服务器返回了-1。请联系技术人员核对时间戳是否正确。";
            throw m;

        }
        else if (getReturn == -6)
        {

            //如果返回值是-6，往上抛异常
            MyException m = new MyException("返回-6,冲突，请重试！");
            throw m;

        }
        return getReturn;
    }

    /// <summary>
    /// 传入一个表名，实例化该同步表的对象
    /// </summary>
    /// <param name="tableName"></param>
    /// <param name="m"></param>
    /// <returns></returns>
    private static tongbu instanceObjectM(string tableName, tongbu m)
    {

        if (tableName == "sys_workshop")
        {
            m = new sys_workshop();
        }
        else if (tableName == "sys_user")
        {
            m = new sys_user();
        }
        else if (tableName == "sys_payment")
        {
            m = new sys_payment();
        }
        else if (tableName == "syskindacc")
        {
            m = new syskindacc();
        }
        else if (tableName == "fitness_checkin")
        {
            m = new fitness_checkin();
        }
        else if (tableName == "pos_bill_payment")
        {
            m = new pos_bill_payment();
        }
        else if (tableName == "pos_sales")
        {
            m = new pos_sales();
        }
        else if (tableName == "pos_bills")
        {
            m = new pos_bills();
        }
        else if (tableName == "fitness_cardchange")
        {
            m = new fitness_cardchange();
        }
        else if (tableName == "jxc_bm_ck")
        {
            m = new jxc_bm_ck();
        }
        else if (tableName == "memcardlog")
        {
            m = new memcardlog();
        }
        else if (tableName == "mem_member")
        {
            m = new mem_member();
        }
        else if (tableName == "fitness_enroll_qchange")
        {
            m = new fitness_enroll_qchange();
        }
        else if (tableName == "sys_identity")
        {
            m = new sys_identity();
        }
        else if (tableName == "fitness_classes")
        {
            m = new fitness_classes();
        }
        else if (tableName == "mem_kind")
        {
            m = new mem_kind();
        }
        else if (tableName == "SnArt")
        {
            m = new SnArt();
        }
        else if (tableName == "gym_reserve")
        {
            m = new gym_reserve();
        }
        else if (tableName == "fitness_enroll")
        {
            m = new fitness_enroll();
        }
        else if (tableName == "gym_period")
        {
            m = new gym_period();
        }
        else if (tableName == "t_fsl_sk_student05")
        {
            m = new t_fsl_sk_student05();
        }
        else if (tableName == "gym_item")
        {
            m = new gym_item();
        }
        else if (tableName == "fitness_monthfee")
        {
            m = new fitness_monthfee();
        }
        else if (tableName == "gym_kind")
        {
            m = new gym_kind();
        }
        else if (tableName == "jxc_dj_kc_2")
        {
            m = new jxc_dj_kc_2();
        }
        else if (tableName == "jxc_dj_kc_zc_2")
        {
            m = new jxc_dj_kc_zc_2();
        }
        else if (tableName == "jxc_dj_kc_db_2")
        {
            m = new jxc_dj_kc_db_2();
        }
        else if (tableName == "jxc_dj_xs_2")
        {
            m = new jxc_dj_xs_2();
        }
        else if (tableName == "jxc_dj_gh_2")
        {
            m = new jxc_dj_gh_2();
        }
        else if (tableName == "jxc_bm_sp")
        {
            m = new jxc_bm_sp();
        }
        else if (tableName == "jxc_zb_sp_kc")
        {
            m = new jxc_zb_sp_kc();
        }
        else if (tableName == "gym_status")
        {
            m = new gym_status();
        }
        else if (tableName == "card_times_info")
        {
            m = new card_times_info();
        }

        return m;
    }

    //根据sql读取记录，并将所有记录的内容读入到一个map的list中
    public static List<Dictionary<String, object>> toDicts(string sql, SqlConnection conn)
    {

        SqlCommand command = new SqlCommand(sql, conn);
        List<Dictionary<String, object>> dicts = new List<Dictionary<String, object>>();
        try
        {
            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Dictionary<String, object> dict = new Dictionary<String, object>();
                    //if(@switch==true)
                    //saveErrLog("toDicts-reader != null && reader.HasRows", "log");
                    Object[] values = new Object[reader.FieldCount];
                    int fieldCount = reader.GetValues(values);
                    for (int i = 0; i < fieldCount; i++)
                    {
                        if (values[i] == DBNull.Value)
                        {
                            dict[reader.GetName(i)] = "";
                        }
                        else
                        {
                            dict[reader.GetName(i)] = values[i];
                        }
                        //if(@switch==true)
                        //saveErrLog(reader.GetName(i) + "----" + values[i].ToString(), "log");
                    }
                    dicts.Add(dict);
                }
            }

        }
        catch (Exception ex)
        {
            saveErrLog("toDicts-ex:" + ex.Message + "\n\r" + ex.StackTrace, "log");
        }

        return dicts;
    }

    /// <summary>
    /// 如果有时间就转换为带毫秒的格式的时间
    /// </summary>
    /// <param name="reader"></param>
    /// <param name="fieldName"></param>
    /// <returns></returns>
    public static String getDateTimeString(Dictionary<String, object> reader, String fieldName)
    {
        if (reader[fieldName] != DBNull.Value)
        {
            if (reader[fieldName].ToString().Trim() != "")
            {
                try
                {

                    return Convert.ToDateTime(reader[fieldName]).ToString("yyyy-MM-dd HH:mm:ss.fff");
                }
                catch
                {
                    CLRTriggers.saveErrLog("时间转换异常:" + fieldName + ":" + reader[fieldName].ToString() + "\n", "转换异常");
                    return "";
                }
            }
            else
            {
                return "";
            }
        }
        else
        {
            return "";
        }
    }

    /// <summary>
    /// 如果不为空就转换为数字型，否则转换为空字符串
    /// </summary>
    /// <param name="reader"></param>
    /// <param name="fieldName"></param>
    /// <returns></returns>
    public static object getIntString(Dictionary<String, object> reader, String fieldName)
    {
        if (reader[fieldName] != DBNull.Value)
        {
            if (reader[fieldName].ToString().Trim() != "")
            {
                try
                {
                    return Convert.ToInt32(reader[fieldName]); ;
                }
                catch
                {
                    CLRTriggers.saveErrLog("int转换异常:" + fieldName + ":" + reader[fieldName].ToString() + "\n", "转换异常");
                    return "";
                }
            }
            else
            {
                return "";
            }
        }
        else
        {
            return "";
        }
    }

    /// <summary>
    /// 如果不为空就转换为数字型，否则转换为空字符串
    /// </summary>
    /// <param name="reader"></param>
    /// <param name="fieldName"></param>
    /// <returns></returns>
    public static object getDoubleString(Dictionary<String, object> reader, String fieldName)
    {
        if (reader[fieldName] != DBNull.Value)
        {
            if (reader[fieldName].ToString().Trim() != "")
            {
                try
                {
                    return Convert.ToDouble(reader[fieldName]);
                }
                catch
                {
                    CLRTriggers.saveErrLog("double转换异常:" + fieldName + ":" + reader[fieldName].ToString() + "\n", "转换异常");
                    return "";
                }
            }
            else
            {
                return "";
            }
        }
        else
        {
            return "";
        }
    }
    private static Dictionary<int, string> dtPath = new Dictionary<int, string>();
    public static string logPath()
    {
        string CorrectPath = "D:";
        try
        {
            //log.txt路径存放优先级
            //以下任何一个可读写目录都可以
            dtPath[1] = @"D:";
            dtPath[2] = "C:";
            dtPath[3] = "E:";
            dtPath[4] = @"C:\Users\Public\Documents";
            for (int i = 1; i < dtPath.Count + 1; i++)
            {
                //判断是否存在这个路径
                if (Directory.Exists(dtPath[i].ToString()))
                {
                    DirectorySecurity s = new DirectorySecurity(dtPath[i].ToString(), AccessControlSections.Access);
                    //判断目录是否可以访问
                    if (!s.AreAccessRulesProtected)
                    {
                        return dtPath[i].ToString();
                    }
                }
            }
        }
        catch
        {
            //C:\Windows\ServiceProfiles\NetworkService\Documents
            CorrectPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        }
        return CorrectPath;
    }
    #region //保存执行错误的sql
    public static void saveErrLog(string log, string txtName)
    {
        txtName = "log";
        log = DateTime.Now.ToString() + " : " + log;
        string path = logPath();
        if (File.Exists(path + @"\" + txtName + ".txt"))
        {
            StreamWriter SW;
            SW = File.AppendText(path + @"\" + txtName + ".txt");
            SW.WriteLine(log + "\r\n");
            SW.Close();
        }
        else
        {
            StreamWriter SW;
            SW = File.CreateText(path + @"\" + txtName + ".txt");
            SW.WriteLine(log + "\r\n");
            SW.Close();
        }

    }
    #endregion

    //该方法用于验证服务器证书是否合法，当然可以直接返回true来表示验证永远通过。服务器证书具体内容在参数certificate中。可根据个人需求验证
    //该方法在request.GetResponse()时触发
    public static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {

        return true;

    }

    /// <summary>
    /// 返回JSon数据
    /// </summary>
    /// <param name="JSONData">要处理的JSON数据</param>
    /// <param name="Url">要提交的URL</param>
    /// <returns>返回的JSON处理字符串</returns>
    public static int SendToDong8Server(string JSONData, string tableName, SqlConnection conn)
    {
        if (conn.State == System.Data.ConnectionState.Closed || conn.State == System.Data.ConnectionState.Broken)
        {
            conn.Open();
        }
        int result = 0;
        JsonData jdf = null;
        jdf = JsonMapper.ToObject(JSONData);
        //如果同步失败，则要由ets端要产生一个新时间戳
        DateTime now = DateTime.Now;
        jdf["new_timestamp"] = now.ToString("yyyy-MM-dd HH:mm:ss.fff");
        JSONData = JsonMapper.ToJson(jdf);

        string sql = @"insert into t_SyncFinancialRecords
                    (sync_id,club_id,sync_type,data_type,fdate,fstatus,fjson,fdemo)
                    values
                    ('" + jdf["sync_id"] + "',0,'" + jdf["sync_type"] + "','" + jdf["data_type"] + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "',1,'[" + JSONData + "]','0')";

        //如果result的值没有变化，代表可能网络出现问题
        if (result == 0)
        {
            if (exec_sql(sql, conn) > 0)
            {
                if (@switch)
                {
                    //saveErrLog("  POST没有返回结果，请查看是否网络异常,已经存入t_SyncFinancialRecords表监听工具将自动上传。", "log");
                    saveErrLog("  " + jdf["sync_id"] + "已经存入t_SyncFinancialRecords表监听工具将自动上传。", "log");
                }
            }
            else
            {
                saveErrLog("  " + jdf["sync_id"] + "存入t_SyncFinancialRecords表失败。触发强制报错将不能存入数据库。", "log");
                //强制报错
                //MyException m = new MyException("没有返回结果，网络异常，保存记录失败！");
                //throw m;
                return -6;
            }
        }
        //}

        return result;
    }

    /// <summary>
    /// 增删改出错方法
    /// </summary>
    /// <param name="jd_get">接到的json对象</param>
    /// <param name="jd_send">发送的json对象</param>
    /// <returns>返回errCode</returns>
    public static int do_err_work(JsonData jd_get, JsonData jd_send, SqlConnection conn)
    {
        int errCode = 0;
        switch (jd_get["status"].ToString())
        {
            case "-1": errCode = -1; break;//返回重复，就强制报错！
            //存入SyncRecord表 
            case "-2":
                //string sql = @"insert into t_SyncFinancialRecords
                //    (sync_id,club_id,sync_type,data_type,fdate,fstatus,fjson,fdemo)
                //    values
                //    ('" + jd_send["sync_id"] + "'," + gymid + ",'" + jd_send["sync_type"] + "','" + jd_send["data_type"] + "','" + DateTime.Now.ToString() + "',1,'[" + jd_send.ToJson() + "]','-2')";
                //exec_sql(sql, conn);
                errCode = -2;
                break;
            case "-3": saveErrLog("返回重复插入记录。status:" + jd_get["status"].ToString() + "\r\n" + jd_send.ToJson() + "\r\n" + jd_get.ToJson(), "log");
                errCode = -3;
                break;
            case "-4": saveErrLog("返回没有找到相关记录。status:" + jd_get["status"].ToString() + "\r\n" + jd_send.ToJson() + "\r\n" + jd_get.ToJson(), "log");
                errCode = -4;
                break;
            case "-5": saveErrLog("返回重复的同步请求。status:" + jd_get["status"].ToString() + "\r\n" + jd_send.ToJson() + "\r\n" + jd_get.ToJson(), "log");
                errCode = -5;
                break;
            default: saveErrLog("返回的status不在预定行列。status:" + jd_get["status"].ToString() + "\r\n" + jd_send.ToJson() + "\r\n" + jd_get.ToJson(), "log");
                errCode = -6;
                break;
        }
        return errCode;
    }

    /// <summary>
    /// 从数据库获取gymid
    /// </summary>
    /// <returns></returns>
    public static string getLocalORRemoteId(string field)
    {
        SqlDataReader dr;
        string value = "";
        try
        {

            using (SqlConnection conn = new SqlConnection(@"context connection=true"))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(@"select top 1 " + field + " from SYS_COMPANY where LocalId is not null;", conn);
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    value = dr[field].ToString();

                }

                dr.Close();
            }

        }
        catch (Exception ex)
        {
            saveErrLog("  获取LocalId失败。" + "  \n\r  " + ex.Message, "log");

        }
        return value;
    }

    #region //根据传入的sql语句返回受影响的行数

    public static int exec_sql(string sql, SqlConnection conn)
    {
        int result = 0;
        //SqlConnection conn = new SqlConnection(@"context connection=true");
        try
        {
            SqlCommand cmd = new SqlCommand(sql, conn);
            // cmd.CommandTimeout = 50000;
            if (conn.State == System.Data.ConnectionState.Closed || conn.State == System.Data.ConnectionState.Broken)
            {
                conn.Open();
            }
            result = cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        catch (Exception ex)
        {
            saveErrLog("\r\n" + ex.Message + "\r\n" + ex.StackTrace.ToString(), "log");
        }

        if (result > 0)
        {
            if (@switch)
            {
                saveErrLog("执行成功的sql : " + sql, "log");
            }
        }
        else
        {
            saveErrLog("执行失败的sql : " + sql, "log");
        }
        return result;
    }
    #endregion

    /// <summary>
    /// 判断是否有监听工具发出的上下文信号
    /// 如果信号对的话返回true
    /// </summary>
    /// <param name="connection">传入连接</param>
    /// <returns>返回是否含有信号</returns>
    public static Boolean hasContextInfo(SqlConnection connection)
    {
        Byte[] bytes = new Byte[1024];

        using (SqlDataReader dr = openReader(connection, "select CONTEXT_INFO() 'CONTEXT_INFO'"))
        {
            if (dr["CONTEXT_INFO"] == DBNull.Value)
            {
                if (@switch)
                {
                    saveErrLog("CONTEXT_INFO:dbnull", "log");
                }
                return false;
            }
            else
            {
                if (@switch)
                {
                    saveErrLog("CONTEXT_INFO:" + BitConverter.ToString((Byte[])dr["CONTEXT_INFO"]), "log");
                }
                if (bytesToHexString((Byte[])dr["CONTEXT_INFO"]) == "123456789")
                {
                    if (@switch)
                    {
                        saveErrLog("CONTEXT_INFO: return true", "log");
                    }
                    return true;
                }
            }
        }
        saveErrLog("CONTEXT_INFO: return false", "log");
        return false;
    }

    /// <summary>
    /// byte数组转换成string
    /// </summary>
    /// <param name="bytes"></param>
    /// <returns></returns>
    public static String bytesToHexString(byte[] bytes)
    {
        String s = BitConverter.ToString(bytes).Replace("-", "").Replace("0", "");
        return s;
    }

    public static SqlDataReader openReader(SqlConnection connection, string sql)
    {
        SqlCommand command = new SqlCommand(sql, connection);
        SqlDataReader reader = command.ExecuteReader();
        reader.Read();
        return reader;
    }

    public static String getValue(SqlDataReader reader, string fieldName)
    {
        try
        {
            if (reader != null)
            {
                Object v = reader[fieldName];
                if (v == DBNull.Value)
                {
                    saveErrLog(fieldName + "is dbnull", "log");
                    return "";
                }
                if (v == null)
                {
                    saveErrLog(fieldName + "is null", "log");
                    return "";
                }
                return v.ToString();
            }
            return "";

        }
        catch (Exception e)
        {
            saveErrLog(e.Message + "\r\n" + e.StackTrace, "log");
            return "";
        }
    }


}


